//
//  Analysis.m
//  CapAnalysis
//
//  Created by 李加建 on 2022/8/29.
//

#import "Analysis.h"

#import <Bugly/Bugly.h>
#import <UMPush/UMessage.h>
#import <UMCommon/UMCommon.h>

@implementation Analysis

/// 使用指定配置初始化Bugly
/// @param appId appId
+ (void)startWithAppId:(NSString*)appId {
    BuglyConfig * config = [BuglyConfig new];
    [Bugly startWithAppId:appId config:config];
}


/// 初始化友盟所有组件产品
/// @param appKey 开发者在友盟官网申请的appkey.
/// @param channel 渠道标识，可设置nil表示"App Store".
+ (void)initWithAppkey:(NSString *)appKey channel:(NSString *)channel {
    [UMConfigure initWithAppkey:appKey channel:channel];
}

/// 友盟推送的注册接口
/// @param launchOptions 系统的launchOptions启动消息参数用于处理用户通过消息打开应用相关信息。
/// @param complete  iOS10授权后的回调
+ (void)registerWithLaunchOptions:(NSDictionary * __nullable)launchOptions complete:(void (^ __nullable)(BOOL granted, NSError *_Nullable error))complete {
    // Push功能配置
    UMessageRegisterEntity* entity = [[UMessageRegisterEntity alloc] init];
    entity.types = UMessageAuthorizationOptionBadge |
                    UMessageAuthorizationOptionAlert |
                    UMessageAuthorizationOptionSound;
    
//    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    
    [UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity completionHandler:complete];
}

/// 向友盟注册该设备的deviceToken，便于发送Push消息
/// @param deviceToken APNs返回的deviceToken
+ (void)registerDeviceToken:( NSData * __nullable)deviceToken {
    [UMessage registerDeviceToken:deviceToken];
}


/// 应用处于运行时（前台、后台）的消息处理，回传点击数据
/// @param userInfo 消息参数
+ (void)didReceiveRemoteNotification:( NSDictionary * __nullable)userInfo {
    [UMessage didReceiveRemoteNotification:userInfo];
}

+ (void)setAlias:(NSString * __nonnull )name type:(NSString * __nonnull)type response:(void (^__nonnull)(id __nullable responseObject,NSError * __nullable error))handle {
    [UMessage setAlias:name type:type response:handle];
}

+ (void)removeAlias:(NSString * __nonnull)name type:(NSString * __nonnull)type response:(void (^__nonnull)(id __nullable responseObject, NSError * __nullable error))handle {
    [UMessage removeAlias:name type:type response:handle];
}

@end
